package com.company.card_service.controller;


import com.company.card_service.model.CompanyCaseType;
import com.company.card_service.model.CompanyModel;
import com.company.card_service.model.Passage;
import com.company.card_service.service.CompanyCaseTypeService;
import com.company.card_service.service.CompanyModelService;
import com.company.card_service.service.PassageService;
import com.company.card_service.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 赵志浩
 * @since 2022-09-15 04:15:06
 */
@RestController
@RequestMapping("/company/companyCaseType")
@Api(tags = "后台管理系统-个性化内容接口")
public class CompanyCaseTypeController {

    @Autowired
    private CompanyCaseTypeService companyCaseTypeService;

    @Autowired
    private CompanyModelService companyModelService;

    @Autowired
    private PassageService passageService;


    @GetMapping("getCompanyCaseTypeInfo/{sysUserId}/{modelId}/{page}/{limit}")
    @ApiOperation("分类管理接口")
    public Result getCompanyCaseTypeInfo(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "sysUserId", value = "当前登录用户id", required = true)
            @PathVariable Integer sysUserId,
            @ApiParam(name = "modelId", value = "当前模块id", required = true)
            @PathVariable Integer modelId){
        List<CompanyCaseTypeVo> companyCaseTypeInfo = companyCaseTypeService.getCompanyCaseTypeInfo(page,limit,sysUserId, modelId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),companyCaseTypeInfo);
    }

    @GetMapping("findNext/{sysUserId}/{modelId}/{caseTypeId}")
    @ApiOperation("下移")
    public Result findNext(
            @ApiParam(name = "sysUserId", value = "系统管理员id", required = true)
            @PathVariable Integer sysUserId,
            @ApiParam(name = "modelId", value = "当前模块id", required = true)
            @PathVariable Integer modelId,
            @ApiParam(name = "caseTypeId", value = "分类类型id", required = true)
            @PathVariable Integer caseTypeId){
        companyCaseTypeService.findNext(sysUserId,modelId,caseTypeId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("findPre/{sysUserId}/{modelId}/{caseTypeId}")
    @ApiOperation("上移")
    public Result findPre(
            @ApiParam(name = "sysUserId", value = "系统管理员id", required = true)
            @PathVariable Integer sysUserId,
            @ApiParam(name = "modelId", value = "当前模块id", required = true)
            @PathVariable Integer modelId,
            @ApiParam(name = "caseTypeId", value = "分类类型id", required = true)
            @PathVariable Integer caseTypeId){
        companyCaseTypeService.findPre(sysUserId,modelId,caseTypeId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("getModel/{modelId}")
    @ApiOperation("获取公司模块")
    public Result getModel(
            @ApiParam(name = "modelId", value = "当前模块id", required = true)
            @PathVariable Integer modelId){
        CompanyModel companyModel =  companyModelService.getModel(modelId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),companyModel);
    }

    @PutMapping("updateModel")
    @ApiOperation("修改公司模块")
    public Result updateModel(@RequestBody CompanyModel companyModel){
        companyModelService.updateById(companyModel);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @PutMapping("addCaseTpye")
    @ApiOperation("新增公司分类")
    public Result addCaseTpye(@RequestBody CompanyCaseType companyCaseType){
        companyCaseTypeService.addCaseTpye(companyCaseType);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @DeleteMapping("deleteCaseType/{caseTypeId}")
    @ApiOperation("删除公司分类")
    public Result deleteCaseType(
            @ApiParam(name = "caseTypeId",value = "分类类型id")
            @PathVariable Integer caseTypeId){
        companyCaseTypeService.removeById(caseTypeId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("getCaseType/{caseTypeId}")
    @ApiOperation("修改公司分类-获取公司分类")
    public Result getCaseType(
            @ApiParam(name = "caseTypeId", value = "当前分类id", required = true)
            @PathVariable Integer caseTypeId){
        CompanyCaseType companyCaseType =  companyCaseTypeService.getCaseType(caseTypeId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),companyCaseType);
    }

    @PutMapping("updateCaseType")
    @ApiOperation("修改公司分类")
    public Result updateCaseType(@RequestBody CompanyCaseType companyCaseType){
        companyCaseTypeService.updateById(companyCaseType);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("getAllPassage/{sysUserId}/{page}/{limit}")
    @ApiOperation("获取所有文章")
    public Result getAllPassage(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "sysUserId", value = "系统管理员id", required = true)
            @PathVariable Integer sysUserId){
        List<PassageFromVo> allPassage = companyCaseTypeService.getAllPassage(page,limit,sysUserId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),allPassage);
    }

    @DeleteMapping("deletePassageById/{passageId}")
    @ApiOperation("删除文章")
    public Result deletePassageById(
            @ApiParam(name = "passageId",value = "文章id")
            @PathVariable Integer passageId){
        passageService.removeById(passageId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("getCaseTypeName/{companyId}")
    @ApiOperation("获取文章新增中的所属分类")
    public Result getCaseTypeName(
            @ApiParam(name = "companyId", value = "公司id", required = true)
            @PathVariable Integer companyId){
        List<CompanyCaseType> caseTypeName = companyCaseTypeService.getCaseTypeName(companyId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),caseTypeName);
    }

    @PostMapping("addPassage")
    @ApiOperation("新增文章")
    public Result addPassage(@RequestBody Passage passage){
        passageService.save(passage);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("getPassageById/{passageId}")
    @ApiOperation("修改文章-获取文章")
    public Result getPassageById(
            @ApiParam(name = "passageId", value = "文章id", required = true)
            @PathVariable Integer passageId){
        Passage passage = passageService.getById(passageId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),passage);
    }

    @PutMapping("updatePassage")
    @ApiOperation("修改文章")
    public Result updateCaseType(@RequestBody Passage passage){
        passageService.updateById(passage);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("selectPassage/{page}/{limit}")
    @ApiOperation("查询文章")
    public Result selectPassage(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "passageQueryVo", value = "查找对象", required = false)
            PassageQueryVo passageQueryVo){
        List<PassageFromVo> passageList = passageService.selectPassage(page,limit,passageQueryVo);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),passageList);
    }

}

